package com.yphone.ui.dialog;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.ContextWrapper;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.WindowManager.LayoutParams;
import android.widget.TextView;

import com.zzkj.yunphone.R;


public class CommSmallLoadingDialog extends Dialog {
    /* access modifiers changed from: private */
    public static CommSmallLoadingDialog dialog;
    private TextView id_msg;
    private boolean isCancle;
    private Activity mParentActivity;
    private String msg;

    public CommSmallLoadingDialog(Context context, String msg2, boolean isCancle2) {
        super(context, R.style.ui_comm_dialog);
        this.msg = msg2;
        this.isCancle = isCancle2;
        this.mParentActivity = getContext(context);
    }

    public CommSmallLoadingDialog(Context context, String msg2) {
        super(context, R.style.ui_comm_dialog);
        this.msg = msg2;
        this.mParentActivity = getContext(context);
    }

    private Activity getContext(Context context) {
        if (context instanceof Activity) {
            return (Activity) context;
        }
        while (context instanceof ContextWrapper) {
            if (context instanceof Activity) {
                return (Activity) context;
            }
            context = ((ContextWrapper) context).getBaseContext();
        }
        return null;
    }

    public static void showDialog(Context context, String msg2, boolean isCancle2) {
        if (dialog == null) {
            dialog = new CommSmallLoadingDialog(context, msg2, isCancle2);
        } else {
            dismissDialog();
            dialog = new CommSmallLoadingDialog(context, msg2, isCancle2);
        }
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }

    public static void showDialog(Context context, String msg2) {
        if (dialog == null) {
            dialog = new CommSmallLoadingDialog(context, msg2);
        } else {
            dismissDialog();
            dialog = new CommSmallLoadingDialog(context, msg2);
        }
        if (!dialog.isShowing()) {
            dialog.show();
        }
    }

    public static void dismissDialog() {
        if (dialog != null && dialog.mParentActivity != null) {
            dialog.mParentActivity.runOnUiThread(new Runnable() {
                public void run() {
                    if (CommSmallLoadingDialog.dialog != null) {
                        CommSmallLoadingDialog.dialog.dismiss();
                        CommSmallLoadingDialog.dialog = null;
                    }
                }
            });
        }
    }

    public void dismiss() {
        if (this.mParentActivity != null && !this.mParentActivity.isFinishing()) {
            super.dismiss();
            this.mParentActivity = null;
        }
    }

    /* access modifiers changed from: protected */
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setCancelable(this.isCancle);
        initDataBeforView();
        initView();
    }

    private void initView() {
        setContentView(R.layout.comm_dialog_small_loading);
        this.id_msg = (TextView) findViewById(R.id.id_msg);
        if (TextUtils.isEmpty(this.msg)) {
            this.id_msg.setText("请稍等...");
        } else {
            this.id_msg.setText(this.msg);
        }
    }

    public void initDataBeforView() {
        LayoutParams lp = getWindow().getAttributes();
        getWindow().setGravity(17);
        lp.width = -1;
        getWindow().setAttributes(lp);
    }
}